/**
 * 
 */
package sg.nus.iss.vmcs.gui.elements;

import java.awt.event.ActionListener;
import sg.nus.iss.vmcs.models.Store;
import sg.nus.iss.vmcs.models.StoreItem;

/**
 * Builder for Drink Selection Item Store Viewer
 * @author Philip Chew
 */
public class DrinkSelectionItemStoreViewerBuilder extends StoreViewerBuilder {

	//Standard Items required for a StoreViewer
	private Store store;
	private ActionListener listener;
	
	public DrinkSelectionItemStoreViewerBuilder(Store store, ActionListener listener) {
		this.store = store;
		this.listener = listener;
	}
	
	/* (non-Javadoc)
	 * @see sg.nus.iss.vmcs.gui.elements.StoreViewerBuilder#buildBanner()
	 */
	@Override
	public void buildBanner() {
		//No Banner Required
	}

	/* (non-Javadoc)
	 * @see sg.nus.iss.vmcs.gui.elements.StoreViewerBuilder#buildStoreViewerItems()
	 */
	@Override
	public void buildStoreViewerItems() {

		StoreItem[] storeItems = store.getItems();
		DrinkSelectionItem[] drinkSelItems = new DrinkSelectionItem[storeItems.length];
		
		for(int i = 0; i < drinkSelItems.length; i++) {
			drinkSelItems[i] = new DrinkSelectionItem(new GridItemDisplayStrategy());
			drinkSelItems[i].setIndex(i);
			drinkSelItems[i].setVariableDisplayState(VariableDisplayState.getDisplayState(VariableDisplayState.Type.WarningOff));
			drinkSelItems[i].setDisplay();
			drinkSelItems[i].setActionCommand(String.valueOf(i));
			
			drinkSelItems[i].setName(storeItems[i].getContent().getName());
			drinkSelItems[i].setQuantity(storeItems[i].getQuantity());
			drinkSelItems[i].setValue(storeItems[i].getContent().getValue());
			storeItems[i].registerObserver(drinkSelItems[i]);
		}
		
		storeViewer.setStoreViewerItems(drinkSelItems);
	}

	/* (non-Javadoc)
	 * @see sg.nus.iss.vmcs.gui.elements.StoreViewerBuilder#buildListeners()
	 */
	@Override
	public void buildListeners() {
		storeViewer.setListener(listener);
	}
}
